package cn.tedu.hotel.controller;

import cn.tedu.hotel.pojo.dto.RoomAddNewDTO;
import cn.tedu.hotel.pojo.vo.RoomListItemVO;
import cn.tedu.hotel.service.IRoomService;
import cn.tedu.hotel.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *   处理房间数据相关的控制器类
 */

@Api(tags = "04. 房间管理模块")
@Slf4j
@RestController
@RequestMapping("/rooms")
public class RoomController {

    @Autowired
    IRoomService roomService;

    public RoomController(){
        log.debug("创建控制器：RoomController");
    }

    @ApiOperation("添加房间")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(RoomAddNewDTO roomAddNewDTO){
        log.debug("开始处理【添加房间】的请求：{}",roomAddNewDTO);
        roomService.addNew(roomAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除房间")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        log.debug("开始处理【删除房间】的请求：id={}",id);
        roomService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("查询房间列表")
    @ApiOperationSupport(order = 300)
    @GetMapping("")
    public JsonResult<List<RoomListItemVO>> listRoom(){
        log.debug("开始处理【查询房间列表】的请求");
        List<RoomListItemVO> roomListItemVOS = roomService.listRoom();
        return JsonResult.ok(roomListItemVOS);
    }

    @ApiOperation("启用房间")
    @ApiOperationSupport(order = 401)
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult<Void> setEnable(@PathVariable Long id) {
        log.debug("准备处理【启用房间】的请求：id={}", id);
        roomService.setEnable(id);
        return JsonResult.ok();
    }

    @ApiOperation("禁用房间")
    @ApiOperationSupport(order = 402)
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult<Void> setDisable(@PathVariable Long id) {
        log.debug("准备处理【禁用房间】的请求：id={}", id);
        roomService.setDisable(id);
        return JsonResult.ok();
    }


    @ApiOperation("设置房间状态为空闲")
    @ApiOperationSupport(order = 501)
    @PostMapping("/{id:[0-9]+}/start/leissure")
    public JsonResult<Void> setLeisure(@PathVariable Long id){
        log.debug("开始处理【修改房间状态为空闲】的请求，房间id={}",id);
        roomService.setLeisure(id);
        return JsonResult.ok();
    }

    @ApiOperation("设置房间状态为占用")
    @ApiOperationSupport(order = 502)
    @PostMapping("/{id:[0-9]+}/start/occupy")
    public JsonResult<Void> setOccupy(@PathVariable Long id){
        log.debug("开始处理【修改房间状态为占用】的请求，房间id={}",id);
        roomService.setOccupy(id);
        return JsonResult.ok();
    }

    @ApiOperation("设置房间状态为异常")
    @ApiOperationSupport(order = 503)
    @PostMapping("/{id:[0-9]+}/start/abnormal")
    public JsonResult<Void> setAbnormal(@PathVariable Long id){
        log.debug("开始处理【修改房间状态为异常】的请求，房间id={}",id);
        roomService.setAbnormal(id);
        return JsonResult.ok();
    }



}
